package com.wind;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WindType {

	private String code = null;
	
	private String name = null;
	
	private WindDatastoreService service = null;

	private Map<String,WindTypeAttribute> attributes = new HashMap<String,WindTypeAttribute>();
	
	private List<WindConstraint> constraints = new ArrayList<WindConstraint>();
	
	public WindType(String code, String name, WindDatastoreService service) {
		this.code = code;
		this.name = name;
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public WindDatastoreService getService() {
		return service;
	}

	public void setService(WindDatastoreService service) {
		this.service = service;
	}
	
	public WindTypeAttribute addAttribute(String code, String name, boolean isNotNull, boolean isUnique) {
		WindTypeAttribute attribute = new WindTypeAttribute(code, name);
		this.attributes.put(attribute.getCode(), attribute);
		
		if(isNotNull) {
			attribute.addConstraint(WindConstraintNotNull.getInstance());
		}
		
		if(isUnique) {
			attribute.addConstraint(WindConstraintUnique.getInstance());
		}
		
		return attribute;
	}
	
	public WindTypeAttribute[] attributes() {
		return (WindTypeAttribute[]) this.attributes.values().toArray();
	}
	
	public void addConstraint(WindConstraint constraint) {
		this.constraints.add(constraint);
	}
	
	public WindConstraint[] constraints() {
		return (WindConstraint[])this.constraints.toArray();
	}
}
